import React, { Component } from 'react'
import { StatusBar, AsyncStorage, View } from 'react-native'
import FooterNavigation from '../Navigation/FooterNavigation'
import Push from '../Lib/Push'

import UserActions from '../Redux/UserRedux'

import { connect } from 'react-redux'
import styles from './Styles/LaunchScreenStyles'

class LaunchScreen extends Component {
  componentDidMount() {
    AsyncStorage.getItem('token')
      .then((token) => this.props.getUser(token))
      .catch((error) => console.error(error))
    Push.getDeviceId((error, result) => {
      if (error) {
        console.error(error)
      } else {
        this.setState({deviceId: result})
      }
    })
  }
  render () {
    return (
      <View style={styles.mainContainer}>
        <FooterNavigation navigation={this.props.navigation} />
      </View>
    )
  }
}
LaunchScreen.router = FooterNavigation.router

const mapStateToProps = (state) => {
  return {
  }
}
const mapDispatchToProps = (dispatch) => {
  return {
    getUser: (token, deviceId) => dispatch(UserActions.userRequest(token, deviceId)),
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(LaunchScreen)
